package com.androidx.p013lv.mine.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.MineBuyVideoAdapter;
import com.androidx.p013lv.mine.bean.CollectVideoBean;
import com.androidx.p013lv.mine.databinding.FragmentBuyVideoBinding;
import com.androidx.p013lv.mine.model.MineBuyVideoModel;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;

/* renamed from: com.androidx.lv.mine.fragment.BuyVideoFragment */
public class BuyVideoFragment extends LazyFragment<FragmentBuyVideoBinding> implements ItemClickListener, OnRefreshLoadMoreListener {
    private MineBuyVideoAdapter adapter;
    private MineBuyVideoModel model;
    private int page = 1;

    public static BuyVideoFragment newInstance() {
        Bundle bundle = new Bundle();
        BuyVideoFragment buyVideoFragment = new BuyVideoFragment();
        buyVideoFragment.setArguments(bundle);
        return buyVideoFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_buy_video;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.model = (MineBuyVideoModel) new ViewModelProvider(this).get(MineBuyVideoModel.class);
        MineBuyVideoAdapter mineBuyVideoAdapter = new MineBuyVideoAdapter();
        this.adapter = mineBuyVideoAdapter;
        mineBuyVideoAdapter.setItemListener(this);
        ((FragmentBuyVideoBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        ((FragmentBuyVideoBinding) this.binding).recycler.setAdapter(this.adapter);
        ((FragmentBuyVideoBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.BuyVideoFragment.View$OnClickListenerC13071 */

            public void onClick(View view) {
                BuyVideoFragment.this.page = 1;
                ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatus(2);
                BuyVideoFragment.this.model.getBuyVideoList(BuyVideoFragment.this.page);
            }
        });
        ((FragmentBuyVideoBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentBuyVideoBinding) this.binding).refresh.setOnLoadMoreListener(this);
        this.model.data().observe(this, new Observer<BaseRes<CollectVideoBean>>() {
            /* class com.androidx.p013lv.mine.fragment.BuyVideoFragment.C13082 */

            public void onChanged(BaseRes<CollectVideoBean> baseRes) {
                BuyVideoFragment.this.hideLoading();
                if (baseRes.getCode() == 200) {
                    CollectVideoBean data = baseRes.getData();
                    if (BuyVideoFragment.this.page == 1) {
                        if (data == null || data.getList() == null || data.getList().size() == 0) {
                            ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatus(4);
                            return;
                        }
                        List<VideoBean> list = data.getList();
                        BuyVideoFragment.this.adapter.setDomain(data.getDomain());
                        BuyVideoFragment.this.adapter.setData(list);
                        if (list.size() < 30) {
                            ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatusRefresh(2);
                        }
                    } else if (data == null || data.getList() == null || data.getList().size() == 0) {
                        ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatusRefresh(2);
                    } else {
                        List<VideoBean> list2 = data.getList();
                        int total = data.getTotal();
                        BuyVideoFragment.this.adapter.setDatasInEnd(list2);
                        if (total < 30) {
                            ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatusRefresh(2);
                        }
                    }
                } else if (BuyVideoFragment.this.page == 1) {
                    ((FragmentBuyVideoBinding) BuyVideoFragment.this.binding).setStatus(1);
                } else {
                    ToastUtils.getInstance().showWrong(baseRes.getMsg());
                }
            }
        });
        ((FragmentBuyVideoBinding) this.binding).setStatus(2);
        this.model.getBuyVideoList(this.page);
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            startVideoPlay(((VideoBean) this.adapter.getDataInPosition(i)).getVideoId());
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.getBuyVideoList(i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        this.model.getBuyVideoList(1);
    }

    public void hideLoading() {
        ((FragmentBuyVideoBinding) this.binding).setStatus(0);
        ((FragmentBuyVideoBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }
}
